package com.hualan.sfzy.service.impl.permission;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.permission.CompanyMapper;
import com.hualan.sfzy.model.entity.Company;
import com.hualan.sfzy.model.entity.Permission;
import com.hualan.sfzy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CompanyServiceImpl implements BaseService<Company> {
    @Autowired
    private CompanyMapper companyMapper;


    @Override
    public int add(Company company) {
        return companyMapper.insert(company);
    }

    @Override
    public int edit(Company company) {
        return companyMapper.insert( company);
    }

    @Override
    public int remove(Integer id) {
        return companyMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return companyMapper.deleteBatch(ids);
    }

    @Override
    public List<Company> find() {
        return companyMapper.select(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Company company) {
        PageHelper.startPage(pageNum, pageSize);
        List<Company> list = companyMapper.select(company);
        PageInfo<Company> pageInfo = new PageInfo<>(list);
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST,list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        pageMap.put(CommonConstant.TOTAL, pageInfo.getList());
        return pageMap;
    }

    @Override
    public Company findById(Integer id) {
        return companyMapper.selectById(id);
    }
}
